// 简单测试登录功能
const http = require('http');

console.log('=== 测试登录功能 ===\n');

// 测试用户70（明文密码）
const testUser70 = () => {
  return new Promise((resolve) => {
    const data = JSON.stringify({ username: '70', password: '123456' });
    
    const req = http.request({
      hostname: 'localhost',
      port: 3000,
      path: '/api/user/login',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(data)
      }
    }, (res) => {
      let responseData = '';
      res.on('data', (chunk) => responseData += chunk);
      res.on('end', () => {
        console.log('用户70登录测试:');
        console.log('状态码:', res.statusCode);
        console.log('响应数据:', responseData);
        console.log('');
        resolve();
      });
    });
    
    req.on('error', (err) => {
      console.error('请求错误:', err);
      resolve();
    });
    
    req.write(data);
    req.end();
  });
};

// 测试用户test（加密密码）
const testUserTest = () => {
  return new Promise((resolve) => {
    const data = JSON.stringify({ username: 'test', password: 'test' });
    
    const req = http.request({
      hostname: 'localhost',
      port: 3000,
      path: '/api/user/login',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(data)
      }
    }, (res) => {
      let responseData = '';
      res.on('data', (chunk) => responseData += chunk);
      res.on('end', () => {
        console.log('用户test登录测试:');
        console.log('状态码:', res.statusCode);
        console.log('响应数据:', responseData);
        resolve();
      });
    });
    
    req.on('error', (err) => {
      console.error('请求错误:', err);
      resolve();
    });
    
    req.write(data);
    req.end();
  });
};

// 运行测试
async function runTests() {
  await testUser70();
  await testUserTest();
  console.log('测试完成');
}

runTests();